package com.bgs.microservices.service.sms.email.contorller;

import com.bgs.microservices.service.sms.controller.BaseController;
import com.bgs.microservices.service.sms.email.service.impl.EmailServiceImpl;
import com.bgs.microservices.service.sms.response.CommonResult;
import jakarta.mail.MessagingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName EmailController
 * @Description 邮件发送
 * @Author 17179
 * @Date 2023/7/31 11:09
 **/
@RestController
@RequestMapping("/email")
public class EmailController extends BaseController {

    @Autowired
    EmailServiceImpl emailServiceImpl;

    /**
     * @param text 发送邮件内容
     * @param subject 主题
     * @param to 发给谁
     * @param from 发送者
     */
    @GetMapping("/sendEmail")
    public CommonResult sendEmail(String text, String subject, String to, String from){
       return emailServiceImpl.sendEmail(text,subject,to,from);
    }


    /**
     * 发送带有样式的内容
     * @param context 发送邮件内容 包含html
     * @param subject 主题
     * @param to 发给谁
     * @param from 发送者
     */
    @GetMapping("/sendEmailAndHtml")
    public CommonResult sendEmailAndHtml(String context,String subject,String to,String from) throws MessagingException{
        return emailServiceImpl.sendEmailAndHtml(context,subject,to,from);
    }


    /**
     * 发送带有文件（包含普通文件压缩包图片等）的邮件
     * @param text 发送邮件内容
     * @param subject 主题
     * @param to 发给谁
     * @param from 发送者
     * @throws MessagingException
     */
    @GetMapping("/sendEmailAndFile")
    public CommonResult sendEmailAndFile(String text,String subject,String to,String from,String filepath) throws MessagingException{
        return emailServiceImpl.sendEmailAndFile(text,subject,to,from,filepath);
    }

}
